package com.hadoop.mr.io;

import org.apache.hadoop.io.BooleanWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * <p></p>
 *
 * @author Andy
 * @date 2017/10/21
 */
public class CombineValues implements Writable{//WritableComparable<CombineValues> {
    private Text joinKey;
    private BooleanWritable flag;
    private Text secondPart;

    public Text getJoinKey() {
        return joinKey;
    }

    public void setJoinKey(Text joinKey) {
        this.joinKey = joinKey;
    }

    public BooleanWritable getFlag() {
        return flag;
    }

    public void setFlag(BooleanWritable flag) {
        this.flag = flag;
    }

    public Text getSecondPart() {
        return secondPart;
    }

    public void setSecondPart(Text secondPart) {
        this.secondPart = secondPart;
    }

    public CombineValues() {
        this.joinKey =  new Text();
        this.flag = new BooleanWritable();
        this.secondPart = new Text();
    }

    public void set(String joinKey, BooleanWritable flag, String secondPart) {
        this.joinKey = new Text(joinKey);
        this.flag = flag;
        this.secondPart = new Text(secondPart);
    }

    /*@Override
    public int compareTo(CombineValues o) {
        return 0;
    }*/

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        this.joinKey.write(dataOutput);
        this.flag.write(dataOutput);
        this.secondPart.write(dataOutput);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.joinKey.readFields(dataInput);
        this.flag.readFields(dataInput);
        this.secondPart.readFields(dataInput);
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return "[flag="+this.flag.toString()+",joinKey="+this.joinKey.toString()+",secondPart="+this.secondPart.toString()+"]";
    }
}
